package org.admanager.soageneralpattern.plugin.soageneralpattern.diagram.providers;

import java.util.HashSet;
import java.util.IdentityHashMap;
import java.util.Map;
import java.util.Set;

import org.admanager.soageneralpattern.plugin.soageneralpattern.diagram.edit.parts.Component2EditPart;
import org.admanager.soageneralpattern.plugin.soageneralpattern.diagram.edit.parts.ComponentEditPart;
import org.admanager.soageneralpattern.plugin.soageneralpattern.diagram.edit.parts.ComponentReference2EditPart;
import org.admanager.soageneralpattern.plugin.soageneralpattern.diagram.edit.parts.ComponentReferenceEditPart;
import org.admanager.soageneralpattern.plugin.soageneralpattern.diagram.edit.parts.ComponentReferenceTargetEditPart;
import org.admanager.soageneralpattern.plugin.soageneralpattern.diagram.edit.parts.ComponentService2EditPart;
import org.admanager.soageneralpattern.plugin.soageneralpattern.diagram.edit.parts.ComponentServiceEditPart;
import org.admanager.soageneralpattern.plugin.soageneralpattern.diagram.edit.parts.CompositeEditPart;
import org.admanager.soageneralpattern.plugin.soageneralpattern.diagram.edit.parts.ConstraintEditPart;
import org.admanager.soageneralpattern.plugin.soageneralpattern.diagram.edit.parts.ElementMultiplicityEditPart;
import org.admanager.soageneralpattern.plugin.soageneralpattern.diagram.edit.parts.ElementRolesEditPart;
import org.admanager.soageneralpattern.plugin.soageneralpattern.diagram.edit.parts.MultiplicityEditPart;
import org.admanager.soageneralpattern.plugin.soageneralpattern.diagram.edit.parts.PatternEditPart;
import org.admanager.soageneralpattern.plugin.soageneralpattern.diagram.edit.parts.ReferenceEditPart;
import org.admanager.soageneralpattern.plugin.soageneralpattern.diagram.edit.parts.ReferencePromoteEditPart;
import org.admanager.soageneralpattern.plugin.soageneralpattern.diagram.edit.parts.RoleEditPart;
import org.admanager.soageneralpattern.plugin.soageneralpattern.diagram.edit.parts.ServiceEditPart;
import org.admanager.soageneralpattern.plugin.soageneralpattern.diagram.edit.parts.ServicePromoteEditPart;
import org.admanager.soageneralpattern.plugin.soageneralpattern.diagram.part.GeneralSOAPatternECOREMetamodelDiagramEditorPlugin;
import org.eclipse.core.runtime.IAdaptable;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EClassifier;
import org.eclipse.emf.ecore.ENamedElement;
import org.eclipse.emf.ecore.EStructuralFeature;
import org.eclipse.gmf.runtime.emf.type.core.ElementTypeRegistry;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.swt.graphics.Image;

/**
 * @generated
 */
public class GeneralSOAPatternECOREMetamodelElementTypes {

	/**
	 * @generated
	 */
	private GeneralSOAPatternECOREMetamodelElementTypes() {
	}

	/**
	 * @generated
	 */
	private static Map/*[org.eclipse.gmf.runtime.emf.type.core.IElementType, org.eclipse.emf.ecore.ENamedElement]*/elements;

	/**
	 * @generated
	 */
	private static ImageRegistry imageRegistry;

	/**
	 * @generated
	 */
	private static Set/*[org.eclipse.gmf.runtime.emf.type.core.IElementType]*/KNOWN_ELEMENT_TYPES;

	/**
	 * @generated
	 */
	public static final IElementType Pattern_1000 = getElementType("org.admanager.soageneralpattern.plugin.diagram.Pattern_1000"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Component_2001 = getElementType("org.admanager.soageneralpattern.plugin.diagram.Component_2001"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Composite_2002 = getElementType("org.admanager.soageneralpattern.plugin.diagram.Composite_2002"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Multiplicity_2003 = getElementType("org.admanager.soageneralpattern.plugin.diagram.Multiplicity_2003"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Role_2004 = getElementType("org.admanager.soageneralpattern.plugin.diagram.Role_2004"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ComponentService_3001 = getElementType("org.admanager.soageneralpattern.plugin.diagram.ComponentService_3001"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ComponentReference_3002 = getElementType("org.admanager.soageneralpattern.plugin.diagram.ComponentReference_3002"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Reference_3003 = getElementType("org.admanager.soageneralpattern.plugin.diagram.Reference_3003"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Service_3004 = getElementType("org.admanager.soageneralpattern.plugin.diagram.Service_3004"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Component_3005 = getElementType("org.admanager.soageneralpattern.plugin.diagram.Component_3005"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ComponentService_3007 = getElementType("org.admanager.soageneralpattern.plugin.diagram.ComponentService_3007"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ComponentReference_3008 = getElementType("org.admanager.soageneralpattern.plugin.diagram.ComponentReference_3008"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType Constraint_3006 = getElementType("org.admanager.soageneralpattern.plugin.diagram.Constraint_3006"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ElementRoles_4001 = getElementType("org.admanager.soageneralpattern.plugin.diagram.ElementRoles_4001"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ElementMultiplicity_4002 = getElementType("org.admanager.soageneralpattern.plugin.diagram.ElementMultiplicity_4002"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ReferencePromote_4003 = getElementType("org.admanager.soageneralpattern.plugin.diagram.ReferencePromote_4003"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ServicePromote_4004 = getElementType("org.admanager.soageneralpattern.plugin.diagram.ServicePromote_4004"); //$NON-NLS-1$
	/**
	 * @generated
	 */
	public static final IElementType ComponentReferenceTarget_4005 = getElementType("org.admanager.soageneralpattern.plugin.diagram.ComponentReferenceTarget_4005"); //$NON-NLS-1$

	/**
	 * @generated
	 */
	private static ImageRegistry getImageRegistry() {
		if (imageRegistry == null) {
			imageRegistry = new ImageRegistry();
		}
		return imageRegistry;
	}

	/**
	 * @generated
	 */
	private static String getImageRegistryKey(ENamedElement element) {
		return element.getName();
	}

	/**
	 * @generated
	 */
	private static ImageDescriptor getProvidedImageDescriptor(
			ENamedElement element) {
		if (element instanceof EStructuralFeature) {
			EStructuralFeature feature = ((EStructuralFeature) element);
			EClass eContainingClass = feature.getEContainingClass();
			EClassifier eType = feature.getEType();
			if (eContainingClass != null && !eContainingClass.isAbstract()) {
				element = eContainingClass;
			} else if (eType instanceof EClass
					&& !((EClass) eType).isAbstract()) {
				element = eType;
			}
		}
		if (element instanceof EClass) {
			EClass eClass = (EClass) element;
			if (!eClass.isAbstract()) {
				return GeneralSOAPatternECOREMetamodelDiagramEditorPlugin
						.getInstance().getItemImageDescriptor(
								eClass.getEPackage().getEFactoryInstance()
										.create(eClass));
			}
		}
		// TODO : support structural features
		return null;
	}

	/**
	 * @generated
	 */
	public static ImageDescriptor getImageDescriptor(ENamedElement element) {
		String key = getImageRegistryKey(element);
		ImageDescriptor imageDescriptor = getImageRegistry().getDescriptor(key);
		if (imageDescriptor == null) {
			imageDescriptor = getProvidedImageDescriptor(element);
			if (imageDescriptor == null) {
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			getImageRegistry().put(key, imageDescriptor);
		}
		return imageDescriptor;
	}

	/**
	 * @generated
	 */
	public static Image getImage(ENamedElement element) {
		String key = getImageRegistryKey(element);
		Image image = getImageRegistry().get(key);
		if (image == null) {
			ImageDescriptor imageDescriptor = getProvidedImageDescriptor(element);
			if (imageDescriptor == null) {
				imageDescriptor = ImageDescriptor.getMissingImageDescriptor();
			}
			getImageRegistry().put(key, imageDescriptor);
			image = getImageRegistry().get(key);
		}
		return image;
	}

	/**
	 * @generated
	 */
	public static ImageDescriptor getImageDescriptor(IAdaptable hint) {
		ENamedElement element = getElement(hint);
		if (element == null) {
			return null;
		}
		return getImageDescriptor(element);
	}

	/**
	 * @generated
	 */
	public static Image getImage(IAdaptable hint) {
		ENamedElement element = getElement(hint);
		if (element == null) {
			return null;
		}
		return getImage(element);
	}

	/**
	 * Returns 'type' of the ecore object associated with the hint.
	 * 
	 * @generated
	 */
	public static ENamedElement getElement(IAdaptable hint) {
		Object type = hint.getAdapter(IElementType.class);
		if (elements == null) {
			elements = new IdentityHashMap/*[org.eclipse.gmf.runtime.emf.type.core.IElementType, org.eclipse.emf.ecore.ENamedElement]*/();

			elements.put(
					Pattern_1000,
					org.admanager.soageneralpattern.plugin.soageneralpattern.soageneralpatternPackage.eINSTANCE
							.getPattern());

			elements.put(
					Component_2001,
					org.admanager.soageneralpattern.plugin.soageneralpattern.soageneralpatternPackage.eINSTANCE
							.getComponent());

			elements.put(
					Composite_2002,
					org.admanager.soageneralpattern.plugin.soageneralpattern.soageneralpatternPackage.eINSTANCE
							.getComposite());

			elements.put(
					Multiplicity_2003,
					org.admanager.soageneralpattern.plugin.soageneralpattern.soageneralpatternPackage.eINSTANCE
							.getMultiplicity());

			elements.put(
					Role_2004,
					org.admanager.soageneralpattern.plugin.soageneralpattern.soageneralpatternPackage.eINSTANCE
							.getRole());

			elements.put(
					ComponentService_3001,
					org.admanager.soageneralpattern.plugin.soageneralpattern.soageneralpatternPackage.eINSTANCE
							.getComponentService());

			elements.put(
					ComponentReference_3002,
					org.admanager.soageneralpattern.plugin.soageneralpattern.soageneralpatternPackage.eINSTANCE
							.getComponentReference());

			elements.put(
					Reference_3003,
					org.admanager.soageneralpattern.plugin.soageneralpattern.soageneralpatternPackage.eINSTANCE
							.getReference());

			elements.put(
					Service_3004,
					org.admanager.soageneralpattern.plugin.soageneralpattern.soageneralpatternPackage.eINSTANCE
							.getService());

			elements.put(
					Component_3005,
					org.admanager.soageneralpattern.plugin.soageneralpattern.soageneralpatternPackage.eINSTANCE
							.getComponent());

			elements.put(
					ComponentService_3007,
					org.admanager.soageneralpattern.plugin.soageneralpattern.soageneralpatternPackage.eINSTANCE
							.getComponentService());

			elements.put(
					ComponentReference_3008,
					org.admanager.soageneralpattern.plugin.soageneralpattern.soageneralpatternPackage.eINSTANCE
							.getComponentReference());

			elements.put(
					Constraint_3006,
					org.admanager.soageneralpattern.plugin.soageneralpattern.soageneralpatternPackage.eINSTANCE
							.getConstraint());

			elements.put(
					ElementRoles_4001,
					org.admanager.soageneralpattern.plugin.soageneralpattern.soageneralpatternPackage.eINSTANCE
							.getElement_Roles());

			elements.put(
					ElementMultiplicity_4002,
					org.admanager.soageneralpattern.plugin.soageneralpattern.soageneralpatternPackage.eINSTANCE
							.getElement_Multiplicity());

			elements.put(
					ReferencePromote_4003,
					org.admanager.soageneralpattern.plugin.soageneralpattern.soageneralpatternPackage.eINSTANCE
							.getReference_Promote());

			elements.put(
					ServicePromote_4004,
					org.admanager.soageneralpattern.plugin.soageneralpattern.soageneralpatternPackage.eINSTANCE
							.getService_Promote());

			elements.put(
					ComponentReferenceTarget_4005,
					org.admanager.soageneralpattern.plugin.soageneralpattern.soageneralpatternPackage.eINSTANCE
							.getComponentReference_Target());
		}
		return (ENamedElement) elements.get(type);
	}

	/**
	 * @generated
	 */
	private static IElementType getElementType(String id) {
		return ElementTypeRegistry.getInstance().getType(id);
	}

	/**
	 * @generated
	 */
	public static boolean isKnownElementType(IElementType elementType) {
		if (KNOWN_ELEMENT_TYPES == null) {
			KNOWN_ELEMENT_TYPES = new HashSet/*[org.eclipse.gmf.runtime.emf.type.core.IElementType]*/();
			KNOWN_ELEMENT_TYPES.add(Pattern_1000);
			KNOWN_ELEMENT_TYPES.add(Component_2001);
			KNOWN_ELEMENT_TYPES.add(Composite_2002);
			KNOWN_ELEMENT_TYPES.add(Multiplicity_2003);
			KNOWN_ELEMENT_TYPES.add(Role_2004);
			KNOWN_ELEMENT_TYPES.add(ComponentService_3001);
			KNOWN_ELEMENT_TYPES.add(ComponentReference_3002);
			KNOWN_ELEMENT_TYPES.add(Reference_3003);
			KNOWN_ELEMENT_TYPES.add(Service_3004);
			KNOWN_ELEMENT_TYPES.add(Component_3005);
			KNOWN_ELEMENT_TYPES.add(ComponentService_3007);
			KNOWN_ELEMENT_TYPES.add(ComponentReference_3008);
			KNOWN_ELEMENT_TYPES.add(Constraint_3006);
			KNOWN_ELEMENT_TYPES.add(ElementRoles_4001);
			KNOWN_ELEMENT_TYPES.add(ElementMultiplicity_4002);
			KNOWN_ELEMENT_TYPES.add(ReferencePromote_4003);
			KNOWN_ELEMENT_TYPES.add(ServicePromote_4004);
			KNOWN_ELEMENT_TYPES.add(ComponentReferenceTarget_4005);
		}
		return KNOWN_ELEMENT_TYPES.contains(elementType);
	}

	/**
	 * @generated
	 */
	public static IElementType getElementType(int visualID) {
		switch (visualID) {
		case PatternEditPart.VISUAL_ID:
			return Pattern_1000;
		case ComponentEditPart.VISUAL_ID:
			return Component_2001;
		case CompositeEditPart.VISUAL_ID:
			return Composite_2002;
		case MultiplicityEditPart.VISUAL_ID:
			return Multiplicity_2003;
		case RoleEditPart.VISUAL_ID:
			return Role_2004;
		case ComponentServiceEditPart.VISUAL_ID:
			return ComponentService_3001;
		case ComponentReferenceEditPart.VISUAL_ID:
			return ComponentReference_3002;
		case ReferenceEditPart.VISUAL_ID:
			return Reference_3003;
		case ServiceEditPart.VISUAL_ID:
			return Service_3004;
		case Component2EditPart.VISUAL_ID:
			return Component_3005;
		case ComponentService2EditPart.VISUAL_ID:
			return ComponentService_3007;
		case ComponentReference2EditPart.VISUAL_ID:
			return ComponentReference_3008;
		case ConstraintEditPart.VISUAL_ID:
			return Constraint_3006;
		case ElementRolesEditPart.VISUAL_ID:
			return ElementRoles_4001;
		case ElementMultiplicityEditPart.VISUAL_ID:
			return ElementMultiplicity_4002;
		case ReferencePromoteEditPart.VISUAL_ID:
			return ReferencePromote_4003;
		case ServicePromoteEditPart.VISUAL_ID:
			return ServicePromote_4004;
		case ComponentReferenceTargetEditPart.VISUAL_ID:
			return ComponentReferenceTarget_4005;
		}
		return null;
	}

}
